package com.situ.b2c.register.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.b2c.pojo.User;
import com.situ.b2c.register.service.UserService;
import com.situ.b2c.util.FileUploadUtil;


@WebServlet("/UserRegisterServlet")
public class UserRegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		FileUploadUtil uploadUtil = new FileUploadUtil(request);
		
		String userName = uploadUtil.getParameter("userName");
		System.out.println(userName);
		String userCode = uploadUtil.getParameter("userCode");
		String userPass = uploadUtil.getParameter("userPass");
		
		User user =new User();
		user.setUserName(userName);
		user.setUserCode(userCode);
		user.setUserPass(userPass);
		UserService userService = new UserService();
		userService.saveUser(user);
		
		response.sendRedirect("index.jsp");
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
